package d;
//p207 HashMap集合类应用
import java.util.HashMap;
import java.util.Iterator;
import java.util.Map;
public class demo1 {
    public static void main(String[] args) {
        HashMap hmap = new HashMap();
        hmap.put("1","北京");
        hmap.put("2","上海");
        hmap.put("3","广东");
        hmap.put("4","江西");
        hmap.put("2","四川");
        hmap.put(null,"天津");
        hmap.put("5",null);
        System.out.println("添加元素后,键值对为:");
        Iterator iter = hmap.entrySet().iterator();//使用迭代器遍历集合
        while (iter.hasNext()){
            Map.Entry entry = (Map.Entry)iter.next();
            System.out.println(entry.getKey() + "-" + entry.getValue());
        }
        System.out.println("键值对的个数为:" + hmap.size());
        System.out.println("是否包含键“3”:" + hmap.containsKey("3"));
        System.out.println("是否包含值“上海”:" + hmap.containsValue("上海"));
        hmap.remove("1");
        System.out.println("删除key为“1”后的键值对为:" + hmap);
    }
}
